package util;


import java.util.ArrayList;
import java.util.Collection;


/**
 * responsible for checking format of image files and ZIP Files
 * 
 * note:	There is a problem with the contentType between Eclipse and the Browser.
 * 			In some cases eclipse gives a different contentType while the Browser gives a different
 * 			contentType aswell. To handle this i just added more String Objects
 * 
 * @author cuche
 * @date 21.05.2014
 * 
 */

public class FormatChecker {

	// One for Eclipse and one for Browser
	private static final String ZIP_FORMAT_ECLIPSE = "application/x-zip-compressed";
	private static final String ZIP_FORMAT_BROWSER = "application/zip";
	private static final Collection<String> ALLOWED_FORMATS = new ArrayList<String>();

	
	
	static {
		// format x-png only in eclipse
		ALLOWED_FORMATS.add("image/x-png");
		// format pjpeg only in eclipse
		ALLOWED_FORMATS.add("image/pjpeg");
		// png only in Browser
		ALLOWED_FORMATS.add("image/png");
		// format jpeg only in Browser
		ALLOWED_FORMATS.add("image/jpeg");
		ALLOWED_FORMATS.add("image/gif");
		ALLOWED_FORMATS.add(ZIP_FORMAT_ECLIPSE);
		ALLOWED_FORMATS.add(ZIP_FORMAT_BROWSER);
	}

	/**
	 * checks if contentType is valid
	 * 
	 * @param contentType
	 *            String containing the contentType
	 * @return true if format is allowed, false otherwise
	 */
	public static boolean checkFormat(String contentType) {

		return ALLOWED_FORMATS.contains(contentType);

	}
	/**
	 * checks if contentType is valid for Eclipse
	 * 
	 * @param contentType
	 * @return true if format is allowed, false otherwise
	 */
	public static boolean isZipEclipse(String contentType) {
		return ZIP_FORMAT_ECLIPSE.equals(contentType);
	}
	
	/**
	 * checks if contentType is valid for Browser
	 * 
	 * @param contentType
	 * @return true if format is allowed, false otherwise
	 */
	public static boolean isZip_Browser(String contentType) {
		return ZIP_FORMAT_BROWSER.equals(contentType);
	}

}